package com.jk.controller;

import com.jk.service.EmployeeService;

import com.jk.vo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * Created by ${user} on ${data}.
 */
@RestController
@RequestMapping("login")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("Emplogin")
    public String login(HttpSession session, Employee employee) {
        List<Employee> employeelist= employeeService.login(employee.getEmployeeName());
        //验证登录账号
        if(employeelist.size()==1){
            if (employeelist.get(0).getEmployeePwd().equals(employee.getEmployeePwd())){
                session.setAttribute("employeelog",employeelist.get(0));
                Employee employeelog = (Employee)session.getAttribute("employeelog");
                return "0";//登录成功
            }else{
                return "1";//密码错误
            }
        }else{
            return "2";// 用户不存在
        }
    }
}
